﻿#ifndef EXCELHANDLE_H
#define EXCELHANDLE_H
#include <QObject>
#include <QWidget>
#include <QStringList>
#include <QMap>
class excelHandle:public QObject
{
    Q_OBJECT
public:
    explicit excelHandle(QObject *parent=0):
        QObject(parent)
    {}
    explicit excelHandle(QString filename,QObject *parent = 0){
        Q_UNUSED(parent);
        m_file = filename;
    }

    excelHandle(const excelHandle &user){
        copy(user);
    }

    excelHandle &operator=(const excelHandle & other){
        copy(other);

        return *this;
    }

    excelHandle &operator<<(excelHandle &other){
        copy(other);
        return *this;
    }

    excelHandle &operator>>(excelHandle &other){
        copy(other);
        return *this;
    }
	
    void setItemIndex(QString index){m_itemIndex=index;}
    void setFileName(QString file){m_file=file;}
    void setGroupNum(QString num){m_group=num;}

    void InsertBox(int index,QHash<int,QString> map){m_hashBox.insert(index,map);}
    void InsertPutValue(int index,QHash<int,QString> map){m_hashPutValue.insert(index,map);}

    //new data handle to insert value and box num.
    void InsertBoxAndPutValue(QMap<int,QPair<QString/*boxNum*/,QString/*PutValue*/>>value){m_boxandPutvalue = value;}
    void InsertTBBoxAndPutValue(int index,QMap<int,QPair<QString,QString>> value){m_withTBBoxPutValue.insert(index,value);}

    void insertTable(QString str){
        if(m_tableVector.indexOf(str) != -1)
            m_tableVector.insert(m_tableVector.indexOf(str),str);
        else
            m_tableVector.push_back(str);
    }
    int getTableIndex(QString str){
        if(m_tableVector.indexOf(str) != -1)
            return m_tableVector.indexOf(str);
        return -1;
    }

    QString getGroupNum(){return m_group;}
    QString getFileName(){return m_file;}
    QString getTable(){
        if(!m_tableVector.isEmpty())
            return m_tableVector.first();
        return "";
    }//current tablename
    QVector<QString> getTables(){return m_tableVector;}
    QString getItemIndex(){return m_itemIndex;}
    QHash<int,QHash<int,QString>> getBoxMap(){return m_hashBox;}
    QHash<int,QHash<int,QString>> getPutValueMap(){return m_hashPutValue;}
    QHash<int ,QString> getFirstBoxMap(){if(m_hashBox.begin()!=m_hashBox.end())return m_hashBox.begin().value();}
    QHash<int ,QString> getFirstPutValueMap(){if(m_hashPutValue.begin()!=m_hashPutValue.end())return m_hashPutValue.begin().value();}

    QMap<int,QPair<QString/*boxNum*/,QString/*PutValue*/>> getBoxAndPutValue(){return m_boxandPutvalue;}
    QMap<int,QMap<int,QPair<QString,QString>>> getTBBoxAndPutValue(){return m_withTBBoxPutValue;}
private:
    QString m_itemIndex;
    QString m_group;
    QString m_file;

    QVector<QString> m_tableVector;

    QHash<int ,QString> m_mapBox;
    QHash<int ,QString> m_mapPutvalue;
    QHash<int,QHash<int,QString>> m_hashBox;
    QHash<int,QHash<int,QString>> m_hashPutValue;
    QMap<int,QPair<QString/*boxNum*/,QString/*PutValue*/>> m_boxandPutvalue;

    QMap<int,QMap<int,QPair<QString,QString>>> m_withTBBoxPutValue;
protected:
    virtual void copy(const excelHandle& other)
    {
        this->m_group = other.m_group;
        this->m_itemIndex = other.m_itemIndex;
        this->m_file = other.m_file;

        this->m_tableVector = other.m_tableVector;

        this->m_mapBox = other.m_mapBox;
        this->m_mapPutvalue = other.m_mapPutvalue;
        this->m_hashBox = other.m_hashBox;
        this->m_hashPutValue = other.m_hashPutValue;
        this->m_boxandPutvalue = other.m_boxandPutvalue;
        this->m_withTBBoxPutValue = other.m_withTBBoxPutValue;
    }
	
};
Q_DECLARE_METATYPE(excelHandle)
#endif // EXCELHANDLE_H
